package com.huaxiafinance.management.service.impl;

import com.huaxiafinance.management.mapper.AppVersionMapper;
import com.huaxiafinance.management.model.AppVersion;
import com.huaxiafinance.management.model.AppVersionExample;
import com.huaxiafinance.management.service.AppVersionService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service("appVersionService")
public class AppVersionServiceImpl implements AppVersionService {
	private static final Logger log = Logger.getLogger(AppVersionServiceImpl.class);

	@Autowired
	private AppVersionMapper appVersionMapper;

	@Override
	public List<AppVersion> select() throws Exception {
		AppVersionExample example = new AppVersionExample();
		example.setOrderByClause("version_number desc");
		try {
			return appVersionMapper.selectByExample(example);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return Collections.emptyList();
	}

	@Override
	public boolean insert(AppVersion app) throws Exception {
		int i = 0;
		try {
			i = appVersionMapper.insert(app);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return i > 0;
	}

	@Override
	public boolean update(AppVersion app) throws Exception {
		int i = 0;

		try {
			i = appVersionMapper.updateByPrimaryKeySelective(app);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}

		return i > 0;
	}

	@Override
	public boolean del(Integer id) throws Exception {
		int i = 0;

		try {
			i = appVersionMapper.deleteByPrimaryKey(id);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return i > 0;
	}
}